package com.ws.shop.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Caching;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ws.shop.bean.Page;
import com.ws.shop.dao.MemberDao;
import com.ws.shop.entity.Address;
import com.ws.shop.entity.Loginlog;
import com.ws.shop.entity.Member;
import com.ws.shop.entity.Order;
import com.ws.shop.service.MemberService;

@Service(value="memberService")
public class MemberServiceImpl implements MemberService {

	@Resource(name="memberDao")
	private MemberDao memberDao;
	
	public int rebeat(final long oid,final int uid){
		 return memberDao.rebeat(oid, uid);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Member findMemberById(int id) {
		return memberDao.findMemberById(id);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<Member> findMemberListByRobot(int robot) {
		return memberDao.findMemberListByRobot(robot);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<Map<String,Object>> findHeadRandList(int size) {
		return memberDao.findHeadRandList(size);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Page findMemberListPage(int pageno, int pagesize, String name,
			String mail, int robot) {
		return memberDao.findMemberListPage(pageno,pagesize,name,mail,robot);
	}

	@Transactional(rollbackFor=Exception.class)
	public void saveOrUpdate(Member user) {
		memberDao.saveOrUpdate(user);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Object checkEmail(String email) {
		return memberDao.checkEmail(email);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Object checkLogin(String mail, String password) {
		return memberDao.checkLogin(mail,password);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public boolean checkName(String name) {
		return memberDao.checkName(name);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Object islogin(int userid) {
		return memberDao.islogin(userid);
	}

	@Transactional(rollbackFor=Exception.class)
	public void loginlog(Loginlog loginlog) {
		memberDao.loginlog(loginlog);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public List<Map<String, Object>> memberlogo() {
		return memberDao.memberlogo();
	}
	
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public int updateUserPriority(int uid,int priority){
		return memberDao.updateUserPriority(uid, priority);
	}
	
	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public int saveAddress(Address address){
		return memberDao.saveAddress(address); 
	}
	
	public int getAddressCount(int uid){
		return memberDao.getAddressCount(uid);
	}
	
    public Address getAddressById(final long id){
    	return memberDao.getAddressById(id);
    }
	
    @Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public int updateAddressByid(Address address) {
		return memberDao.updateAddressByid(address);
	}
    
    public List<Address> getAddressByUid(long uid) {
    	return memberDao.getAddressByUid(uid);
    }
    
    @Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public int delAddressById(long id) {
		return memberDao.delAddressById(id);
	}
    
    public int doExpoint(final int uid){
    	return memberDao.doExpoint(uid);
    }
	@Transactional(rollbackFor=Exception.class)
    public int updateUsers(Member member){
    	return memberDao.updateUsers(member);
    }
	
	public int updateUserPassword(final int uid,final String oldpassword,final String newpassword){
		return memberDao.updateUserPassword(uid, oldpassword, newpassword);
	}

	@Caching(evict={@CacheEvict(value="sunpic",key="'findByAId_'+#order.aid",condition="#order.aid > 0"),@CacheEvict(value="sunpicColl",allEntries=true)})
	public int winersaysave(Order order, String word) {
		return memberDao.winersaysave(order, word);
	}
	
	public boolean isUserSunpic(long id,int uid){
		return memberDao.isUserSunpic(id, uid);
	}
	
	public int delImg(final long  id){
		return memberDao.delImg(id);
	}
	
	public String toRegister(final Member member){
		return memberDao.toRegister(member);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED,readOnly=true)
	public Member findMemberByName(String username) {
		return memberDao.findMemberByName(username);
	}
	
	public List<Member> getChirlds(final int uid){
		return memberDao.getChirlds(uid);
	}
	
	public int updateHead(final String head, final int uid){
		return memberDao.updateHead(head, uid);
	}
}
